<template>
  <div class="rightBodyContent">
    <div class="rightBodyContent-in">
      <el-tabs v-model="editForm.style" type="card">
        <el-tab-pane :label="item.name" :name="item.id" v-for="item in tabList" :key="item.id"></el-tab-pane>
      </el-tabs>
      <div class="hearder-search">
        <div class="toplineBox mb-10">
          <div class="toplineBox-left">
            <el-input v-model="editForm.name" placeholder="填写学生姓名" size="small" class="w-140 mr-10"></el-input>
            <el-input v-model="editForm.user_name" placeholder="填写带看人姓名" size="small" class="w-140 mr-10"></el-input>
            <el-select v-model="editForm.is_examine" placeholder="请选择审核状态" size="small" class="w-140 mr-10" v-if="editForm.style=='4'">
              <el-option
                  v-for="item in examineList"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id">
              </el-option>
            </el-select>
            <el-button type="primary" size="small" @click="searchFn"><i class="el-icon-search"></i>搜索</el-button>
            <el-button size="small" @click="refreshFn"><i class="el-icon-refresh"></i>刷新</el-button>
            <downexcel type="examineRecruit" :option="editForm"></downexcel>
          </div>
          <p class="numberline toplineBox-right">总{{ page.total }}条</p>
        </div>
      </div>
      <div class="table-body">
        <div class="table-body-box">
          <el-table
              ref="multipleTable"
              :data="arryList"
              :stripe="tableStyle.tableStripe"
              :border="tableStyle.tableBorder"
              tooltip-effect="dark"
              style="width: 100%"
              header-cell-class-name="table-text-c"
              cell-class-name="table-text-c">
            <el-table-column
                prop="id"
                label="ID"
                width="90"
                :key="1">
            </el-table-column>
            <el-table-column
                prop="name"
                label="标题"
                :key="2">
              <template slot-scope="scope">
                {{ scope.row.recruit ? scope.row.recruit.title : '--' }}
              </template>
            </el-table-column>
            <el-table-column
                prop="name"
                label="学生姓名"
                :key="3">
            </el-table-column>
            <el-table-column
                prop="mobile_phone"
                label="父母电话"
                :key="4">
            </el-table-column>
            <el-table-column
                prop="address"
                label="户籍地"
                :key="5">
            </el-table-column>
            <el-table-column
                prop="address"
                label="预报班级"
                :key="6">
              <template slot-scope="scope">
                {{ scope.row.class_name ? scope.row.class_name : '' }}
              </template>
            </el-table-column>
            <el-table-column
                label="带看人"
                :key="7">
              <template slot-scope="scope">
                {{scope.row.user?scope.row.user.realname: ''}}
              </template>
            </el-table-column>
            <el-table-column
                prop="create_time"
                label="报名时间"
                :key="8">
            </el-table-column>
            <el-table-column
                prop="time"
                label="接待时间"
                :key="9">
            </el-table-column>
            <el-table-column
                prop="time"
                label="审核时间"
                :key="10"
                v-if="editForm.style=='4'">
            </el-table-column>
            <el-table-column
                prop="time"
                label="状态"
                :key="11">
              <template slot-scope="scope">
                <el-link type="success" :underline="false" v-if="editForm.style=='4'&& scope.row.is_examine==1">通过审核
                </el-link>
                <el-link type="danger" :underline="false" v-if="editForm.style=='4'&& scope.row.is_examine==2">驳回申请
                </el-link>
                <el-link type="warning" v-if="editForm.style=='3'" :underline="false">待审核</el-link>
              </template>
            </el-table-column>
            <!--顺序排序-->
            <el-table-column
                label="操作"
                width="160"
                :key="12">
              <template slot-scope="scope">
                <el-button type="primary" size="small" @click="recruitId=scope.row.id,detailVisible=true" plain>招生详情
                </el-button>
              </template>
            </el-table-column>
          </el-table>
        </div>
      </div>
      <!--工具条 分页-->
      <el-col :span="24" class="toolbar">
        <el-pagination
            background
            layout="prev, pager, next"
            :total="page.total"
            :page-size="page.pagesize"
            @current-change="handleSizeChange">
        </el-pagination>
      </el-col>
      <recruitDetail :visible.sync="detailVisible" :recruitId="recruitId" :statusType="editForm.style"
                     @InitFn="InitFn"></recruitDetail>
    </div>
  </div>
</template>

<script>
import {pagination, tableoption} from '@/utils/util.js'
import api from '@/utils/api.js'
import {mapGetters} from "vuex";
import {recuitLogIndex} from '@/api/admin/recuit'
import recruitDetail from "./recruitDetail";

export default {
  props: ['tabchildValue', 'tabValue'],
  components: {
    recruitDetail
  },
  computed: {
    ...mapGetters(['userInfo']),
  },
  watch: {
    'editForm.style'() {
      this.page.pageindex = 1;
      this.editForm.name = '';
      this.editForm.user_name = '';
      this.editForm.is_examine = '';
      this.InitFn()
    }
  },
  data() {
    return {
      tabList: [
        {
          name: '待审核',
          id: '3',
        },
        {
          name: '已审核',
          id: '4'
        }
      ],
      detailVisible: false,
      workeDetailVisible: false,
      arryList: [], // 页面数据列表
      // 搜索设置
      searchWord: '', // 搜索名称
      // 设置table样式
      tableStyle: tableoption,
      // 设置table页面分页所需
      page: {
        pageindex: pagination.pageIndex,
        pagesize: pagination.pageSize,
        total: pagination.total
      },
      recruitId: 0,
      editForm: {
        style: '3',
        name: '',
        type: 2,
        user_name: '',
        is_examine: '',
      },
      userInfomation: null,
      examineList: [
        {
          id:1,
          name: '通过审核'
        },
        {
          id:2,
          name: '驳回申请'
        }
      ]
    }
  },
  created() {
    this.InitFn()
  },
  methods: {
    // 初始化
    async InitFn() {
      let option = this.getJson(this.editForm)
      option.p = this.page.pageindex
      recuitLogIndex(option).then(res => {
        for (let item of res.list.data) {
          item.examine_time = item.examine_time ? item.examine_time.split(' ')[0] : ''
          item.time = item.time.split(' ')[0]
          item.create_time = item.create_time.split(' ')[0]
        }
        this.arryList = res.list.data
        this.page.total = res.list.total
      })
    },
    getJson(item){
      return JSON.parse(JSON.stringify(item))
    },
    searchFn() {
      this.page.pageindex = 1
      this.InitFn()
    },
// 刷新页面
    refreshFn() {
      this.page.pageindex = 1
      this.editForm.name = ''
      this.editForm.user_name = '';
      this.editForm.is_examine = '';
      this.InitFn()
    },
// 分页
    handleSizeChange(val) {
      this.page.pageindex = val
      this.InitFn()
    }
    ,
// 刷新详情信息
    getUser() {
      this.taskDetail(this.editBox, 'refreshFn')
    }
    ,
    handleDetel(index) {
      this.$confirm('确认永久删除, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.detelRespon(index)
      }).catch(() => {
      })
    }
    ,
    detelRespon(index) {
      this.$post(api.task_delete, {id: this.arryList[index].id}).then((response) => {
        if (response.code === 0) {
          this.arryList.splice(index, 1)
          this.$message({
            type: 'success',
            message: '删除成功!'
          })
        } else {
        }
      }).catch((err) => {
        console.log(err)
      })
    }
  },
  mounted() {
  }
}
</script>

<style lang="scss" scoped>
.evaluateBox {
  background: #eee;
  margin-top: 5px;
  border-radius: 4px;
  padding: 5px;
}

.lookLsit {
  cursor: pointer;
}

.lookLsit:hover {
  text-decoration: underline;
}

#tablebox {
  display: flex;
  flex-direction: column;
}

.el-table {
  color: #000;
}

.right-box .container .main .content-container .input-val-box .input-top {
  width: 250px;
}

</style>
